#======================================================================
# Product:      KnowledgeEngine (Plone Version)
#
# File:         AbstractBlogClient.py
#
# Copyright:    Copyright (c) 2006, Faulkner Technologies
#
# Author:       John Meredith
#
# Description:  An abstract blog client. Must be extended.
#======================================================================


#======================================================================
# KnowledgeEngine Imports
#----------------------------------------------------------------------
#from Products.KnowledgeEngine.Actions.BlogPost import BlogPostException

#======================================================================
# Zope Library Imports
#----------------------------------------------------------------------


#======================================================================
# Python Library Imports
#----------------------------------------------------------------------
import os
import sys
import unittest


#======================================================================
# Class definition
#----------------------------------------------------------------------
class AbstractBlogClient:
    """
        An abstract class which defines some methods that should be
        implemented
    """

    # Some meta-data for the blog client
    TITLE = "AbstractBlogClient"
    
    #---------------------------------------------------------------------------
    # Flag to identify whether this API allows for anonymous posting to blogs
    ALLOW_ANONYMOUS = True

    def __init__(self, **args):
        """
            Initialise the instance
        """

        self.username = args.get('username', None)
        self.password = args.get('password', None)
        self.serverURL = args.get('url', None)
        self.extraArguments = args


    def isValidConnection(self):
        """
            Returns true if the connection details given seem to
            be valid.
        """
        
        return False


    def getBlogs(self):
        """
            Return a list of available blogs
        """

        return ()
        

    def createPost(self, **args):
        """
            Create a new post.
        """
        
        return False


    def checkAnonymous(self):
        """
            Throws an exception if the API in question does not allow
            anonymous access
        """
        
        if not self.ALLOW_ANONYMOUS and not self.username:
            raise BlogPostException, "%s does not allow anonymous access i.e. username and password are required" % (self.TITLE, )
